class Solution1 {
    public boolean backspaceCompare(String s, String t) {
        String str1 = backspace(s);
        String str2 = backspace(t);
        if (str1.equals(str2)) {
            return true;
        }
        return false;
    }

    public static String backspace(String str) {
        StringBuffer ret = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            if (ret.length() == 0 && str.charAt(i) == '#') {
                continue;
            }
            if (ret.length() > 0 && str.charAt(i) == '#') {
                ret.deleteCharAt(ret.length() - 1);
            } else {
                ret.append(str.charAt(i));
            }
        }
        return ret.toString();
    }

    public static void main(String[] args) {
        System.out.println(Solution1.backspace("y#f#o##f"));
        System.out.println(Solution1.backspace("y#fo##f"));
    }
}